<template>
    <div class="acceptance-registration-pages">
        
        <commpVxeTable
         :config="dataTableConfig" 
         :columns="columnsVxe" 
         :formItem="formItem"
         @checkboxChange="checkboxChange"
         ref="acceptanceRegistrationRef"
         >
            <template v-slot:fsxmc_name="{row}" data-desc="自定操作栏">
                <span v-if="row.fzwxtbzzt == '补正中'" class="fsxmcQ-c-t">[{{ row.fzwxtbzzt}}]</span>
                <span v-if="row.fzwxtbzzt == '已补正'" class="fsxmcQ-l-t">[{{ row.fzwxtbzzt}}]</span>

                <span v-if="row.fzwxtzgzt == '整改中'" class="fsxmcQ-c-t">[{{ row.fzwxtzgzt }}]</span>
                <span v-if="row.fzwxtzgzt == '已整改'" class="fsxmcQ-l-t">[{{ row.fzwxtzgzt }}]</span>

                <span v-if="row.fzwxtcjzt == '撤件回复'" class="fsxmcQ-h-t" @click="cjhfClick()">[{{ row.fzwxtcjzt }}]</span>
                <span v-if="row.fzwxtcjzt == '撤件审核中'" class="fsxmcQ-c-t">[{{ row.fzwxtcjzt }}]</span>
                <span v-if="row.fzwxtcjzt == '已撤件'" class="fsxmcQ-l-t">[{{ row.fzwxtcjzt }}]</span>

                <span v-if="row.fzwxtthzt" class="fsxmcQ-h-t">{{ row.fzwxtthzt }}</span>
                <span>{{ row.fsxmc }}</span>
            </template>
            <template v-slot:name_fslsj="{row}" data-desc="自定操作栏">
                <span>{{ timeProcessing(row.fslsj) }}</span>
            </template>
            <template v-slot:operation_btn="{row}" data-desc="自定操作栏">
                <a-form layout="inline" class="search-form" >
                    <a-form-item >
                        <a-button class="blue-btn" type="primary" @click="reviseClick(row)">办理</a-button>
                    </a-form-item>
                    <!-- <a-form-item v-if="routeData.fullPath.indexOf('/assessCheck/schemeProduction/index') !== -1">
                        <a-button  class="blue-btn" type="primary" @click="generateQRCode(row)">生成问卷调查二维码</a-button>
                    </a-form-item> -->
                </a-form>
            </template>
        </commpVxeTable>
        <increase
         ref="refModel" 
         :addEditParameter="addEditParameter" 
         @successReturn="successReturn" 
         @flowPathTwoSuccess="successReturn" 
         :flowPath2="flowPath2"
         @reviseClick="reviseClick"
         />
        <a-modal class="QR-code-modal" v-model:visible="QRCodeVisible" title="问卷调查二维码" @cancel="QRCodeVisible = false">
            <div class="qr-img-box">
                <img :src="queryResultsImgUrl" v-if="queryResultsImgUrl"/>
                <span v-else>二维码正在生成中</span>
            </div>
            <div style="display: flex;justify-content: center;margin-top: 15px;" v-if="queryResultsImgUrl">
                <a-button class="blue-btn" type="primary" @click="downloadQRCode(queryResultsImgUrl)">下载二维码</a-button>
                <a-button class="blue-btn" type="primary" @click="jumpClick()">下载二维码</a-button>
            </div>
        </a-modal>
    </div>
</template>
<script>
import {typeInput, typeNumber, typeSelect, typeCheckbox, typeRadio} from '@/components/compSearchCriteria/ContractType'
import assessCheckApi from './service/api.js'
import increase from './increase.vue'
import { deleteArrServe, ocalityPostAction, dateDataServe, duplicateServe, queryJobByJobIdServe, queryAllYbJob } from './service/index'
import commpVxeTable from '@/components/commp-vxe-table/commp-vxe-table.vue'
import moment from 'moment'
import {qrcanvas} from 'qrcanvas'
import blobType from '@/common/blobType'
import { ABackTop } from 'ant-design-vue';
  export default {
    components:{
        increase,
        commpVxeTable,
        ABackTop,
    },
    props:{
        linkName:{
            type:String,
            default: '',
            required:false
        },
    },
    data(){
        return{
            routeData:this.$route,
            addEditParameter:{},
            formItem:[
                {
                    label: '事项名称',
                    model: 'fsxmc',
                },{
                    label: '企业名称',
                    model: 'fqymc',
                },{
                    label: '申请单号',
                    model: 'fsqdbh',
                },{
                    label: '任务编号',
                    model: 'fslbh',
                }

            ],
            columnsVxe:[
                { 
                    type: 'checkbox', 
                    width: 60 ,
                    fixed: 'left'
                },{
                    title: '事项名称', //列头显示文字
                    field: 'fsxmc',
                slots: {
                    default: 'fsxmc_name',
                },
                    fixed: 'left',
                },{
                    title: '企业名称', //列头显示文字
                    field: 'fqymc',
                },{
                    title: '申请单号',
                    field: 'fsqdbh',
                },{
                    title: '任务编号',
                    field: 'fslbh',
                },{
                    title: '接收时间',
                    field: 'fslsj',
                    slots: {
                        // 使用插槽模板渲染
                        default: 'name_fslsj',
                    },
                },{
                    title: '剩余天数',
                    field: 'syday',
                },{
                    title: '操作',
                    field: 'jobid',
                    slots: {
                    // 使用插槽模板渲染
                    default: 'operation_btn',
                  },
                    fixed: 'right',
                    width:260,
                }],
            dataTableConfig:{
                api: assessCheckApi.list,
                rowId: 'jobid',
                fywflcode:blobType.fywflcodeArr[blobType.menuType.indexOf(this.$route.name.substring(this.$route.name.indexOf('__'),this.$route.name.indexOf('_a')+2))],
                paramet:{
                    fhjmc:this.linkName,
                    fblzt:'待办'
                }            
            },
            specifyDateVal:'',
            isSpecifyDate:false,
            numFigure:1,
            currentReplicationId:'',
            selectedRowKeysArr:[],
            flowPath2:{},
            QRCodeVisible:false,
            newImage:new Image(),
            queryResultsQr:null,
            queryResultsImgUrl:'',
            currentRow:{}
        }
    },
    mounted(){
        //console.log('获取当前路由名称',this.$route.fullPath,this.$route.name)
        //console.log('获取当前路由名称',this.$route.fullPath.indexOf('/assessCheck/schemeProduction/index'))
        //console.log('获取当前路由名称',this.$route.fullPath.indexOf('_$'))
        //console.log('获取当前路由名称',this.$route.fullPath.substr(this.$route.fullPath.indexOf('_a')+2,this.$route.fullPath.indexOf('_$')-2))
        //console.log(this.$route.fullPath.indexOf('/assessCheck/schemeReview/schemeReview__drugProduce_a'))
        // this.dataTableConfig.paramet.fhjmc = 
    },
    
    methods:{
        cjhfClick(){
            this.$route.push('/enterpriseWithdrawalApplication/index')
        },
        timeProcessing(val){
            if(val){
                val = val.slice(0,11)
            }
            return val
        },
        async dictionaryQuery(val){
            let dataObj = []
            await ocalityPostAction({dictName:val}).then(res=>{
                //console.log('字典的res',res)
                if(res.code == 200){
                    if(res.result.length){
                        dataObj = res.result
                    }
                    
                }
            })
            return dataObj
        },
        checkboxChange(val){//获取当前选择的行
            //console.log('当前选择表格',val)
            this.selectedRowKeysArr = []
            val.forEach(item => {
                this.selectedRowKeysArr.push(item.jobid)
            });
        },
        specifyDateChange(val){
            //console.log(moment(val).format('YYYY-MM-DD'))
            this.specifyDateVal = moment(val).format('YYYY-MM-DD')
        },
        // selectedRowKeys(keys){//获取选中表格rowKey
        //     this.selectedRowKeysArr = keys
        // },
        successReturn(){
            this.$refs.acceptanceRegistrationRef.searchEvent()
        },
        batchDeletion(){//
            var that = this
            this.$confirm({
                title:'您确认要删除吗？',
                // icon: createVNode(ExclamationCircleOutlined),
                onOk() {
                    if(that.selectedRowKeysArr.length){
                        let deleteString = that.selectedRowKeysArr.join(',')
                        deleteArrServe({ids:deleteString}).then(res=>{
                            if(res.code == 200){
                                that.$message.success('删除成功')
                            }else{
                                that.$message.warning(res.message)
                            }              
                            that.$refs.acceptanceRegistrationRef.searchEvent()
                        })
                    }else{
                        that.$message.warning('请选择删除项')
                    }
                },
                
            });
            
            
        },
        handleOk(val,id){
            if(val && !id){
                this.$refs.acceptanceRegistrationRef.resetEvent()
            }else if(val && id){
                this.requestParams = {
                    ...this.requestParams,
                    renovate:true,
                }
            }
            
        },
        //
        //办理
        reviseClick(val){
            let that = this
            queryJobByJobIdServe({jobid:val.jobid}).then(res=>{
                //console.log('办理',res)
                if(res.code == 200){
                    let fthyjOptions = []
                    queryAllYbJob({jobid:val.jobid}).then(res2=>{
                        if(res2.code == 200){
                            //console.log(res2)
                            res2.result.forEach(item=>{
                                fthyjOptions.push({value:item.id,label:item.fhjmc})
                            })
                            let data = res.result.sqsx
                            that.addEditParameter = {
                                isReadOnly:true,
                                fscms:data.fscms?data.fscms:'技术审评',
                                fywflcode:blobType.fywflcodeArr[blobType.menuType.indexOf(this.$route.name.substring(this.$route.name.indexOf('__'),this.$route.name.indexOf('_a')+2))],
                                jobid:res.result.job.id,
                                sqsxid:data.id,
                                fsxmc:data.fsxmc,
                                fhjmc:res.result.job.fhjmc,
                                fsqsj:data.fsqsj?moment(data.fsqsj).format('YYYY-MM-DD'):'',
                                fjclx:data.fjclx,
                                fslzt:String(data.fslzt),
                                fslsj:data.fslsj?moment(data.fslsj).format('YYYY-MM-DD'):'',
                                fslbh:data.fslbh,
                                fwcsx:data.fwcsx,
                                fjzrq:data.fjzrq,

                                fqyid:data.fqyid,//企业Id
                                fqymc:data.fqymc,
                                ftyshxydm:data.ftyshxydm,
                                fqyfddbrfzr:data.fqyfddbrfzr,
                                fqylxr:data.fqylxr,
                                fqylxrdh:data.fqylxrdh,
                                fqyzszcdz:data.fqyzszcdz,
                                fszdq:data.fszdq,
                                fxxdz:data.fxxdz,

                                fcpmc:data.fcpmc,//产品名称
                                fsqdbh:data.fsqdbh,
                                fspdwmc:data.fspdwmc,
                                fbldwmc:data.fbldwmc,
                                ffsr:data.ffsr,
                                ffssj:data.ffssj,
                                fblr:data.fblr,
                                dbrid:res.result.nextNodeDbrList.length?[res.result.nextNodeDbrList[0].dbrid]:[],
                                opinion:'',//办理意见
                                smgflag:false,//是否发送短信
                                dbridRequired:true,
                                fthyj:res.result.job.fthyj,//退回意见
                                fthyjOptions:fthyjOptions,
                                shjid:fthyjOptions.length?fthyjOptions[0].value:'',
                                fthyjInput:'',
                                fblzt:res.result.job.fblzt,
                                fqyjbxx:data.fqyjbxx,
                                fcyjcfw:data.fcyjcfw,
                                fjcsjjrcap:data.fjcsjjrcap,
                                fcjryjjczfz:data.fcjryjjczfz,
                                fjcxm:data.fjcxm,
                                fjcfajqtyq:data.fjcfajqtyq,
                                fcyjcyj:data.fcyjcyj,
                                fsplx:data.fsplx,
                                ...res.result.qy,
                            }
                            that.flowPath2 = {
                                fsplx:data.fsplx,
                                fywflcode:blobType.fywflcodeArr[blobType.menuType.indexOf(this.$route.name.substring(this.$route.name.indexOf('__'),this.$route.name.indexOf('_a')+2))],
                                jobid:res.result.job.id,
                                sqsxid:data.id,
                                fscms:data.fscms?data.fscms:'技术审评',
                                fcykssj:data.fcykssj,
                                fcyjssj:data.fcyjssj,
                                fcyhbqy:data.fcyhbqy?data.fcyhbqy.split(','):data.fcyhbqy,
                                fcyxzqy:data.fcyxzqy,
                                fcyzytc:data.fcyzytc?data.fcyzytc.split(','):data.fcyzytc,
                                timeArr:data.fcykssj?[data.fcykssj,data.fcyjssj]:[],
                                nextNodeDbrList:res.result.nextNodeDbrList,
                                nextNode:res.result.nextNode,
                                dbrid:res.result.nextNodeDbrList.length?[res.result.nextNodeDbrList[0].dbrid]:[],
                                opinion:'',//办理意见
                                smgflag:false,//是否发送短信
                                fcyfazt:data.fcyfazt,
                                fspfazt:data.fspfazt,
                                fhjmc:res.result.job.fhjmc,

                                //技术
                                fsphbqy:data.fsphbqy?data.fsphbqy.split(','):data.fsphbqy,
                                fspxzqy:data.fspxzqy,
                                fspkssj:data.fspkssj,
                                fspjssj:data.fspjssj,
                                spTimeArr:data.fspkssj?[data.fspkssj,data.fspjssj]:[],
                                fspzytc:data.fspzytc?data.fspzytc.split(','):data.fspzytc,
                                spDbrid:res.result.nextNodeDbrList.length?[res.result.nextNodeDbrList[0].dbrid]:[],
                                spOpinion:'',//办理意见
                                spSmgflag:false,//是否发送短信
                                fthyj:res.result.job.fthyj,//退回意见
                                fthyjOptions:fthyjOptions,
                                shjid:fthyjOptions.length?fthyjOptions[0].value:'',
                                fthyjInput:'',
                                fblzt:res.result.job.fblzt,
                                fqyjbxx:data.fqyjbxx,
                                fcyjcfw:data.fcyjcfw,
                                fjcsjjrcap:data.fjcsjjrcap,
                                fcjryjjczfz:data.fcjryjjczfz,
                                fjcxm:data.fjcxm,
                                fjcfajqtyq:data.fjcfajqtyq,
                                fcyjcyj:data.fcyjcyj,
                                ...res.result.qy,
                                
                                
                            }
                            
                            this.$refs.refModel.visibleShow = true
                            this.$refs.refModel.getData(this.addEditParameter)
                        }
                    })
                }else{
                    this.$message.warning(res.message)
                }
            })
            
            
        },
        
        AddHandleOk(){
            this.$refs.acceptanceRegistrationRef.resetEvent()
        },
        //生成二维码
        generateQRCode(row){
            //console.log('生成二维码',row)
            this.currentRow = row
            this.QRCodeVisible = true
            this.queryResultsQr = qrcanvas({
                data: bootConfig[process.env.NODE_ENV].EXTERNAL_ACCESS_URL+process.env.BASE_URL+`integrityAndSatisfaction?id=`+row.sqsxid   || "二维码生成中",
                size:260,
                background:'#fff',
            })
            this.queryResultsImgUrl = this.newImage.src = this.queryResultsQr.toDataURL("image/png")
        },
        downloadQRCode(val){
            var a = document.createElement("a");
            a.href = val;
            a.setAttribute('download', '审评员自律情况和满意度调查问卷二维码');
            a.click();
            message.success('已下载')
        },
        jumpClick(){
            this.$router.push('/integrityAndSatisfaction?id='+this.currentRow.sqsxid)
        }
    },

  }
</script>
<style lang="less">
.acceptance-registration-pages{
    .select-date-box{
        display: flex;
        flex-direction: column;
        span{
            color: #f5222d;
            font-size: 14px;
        }
    }
    .modal-btn-box{
        .ant-form-item-control{
            width: 175px !important;
        }
    }
    
}
.QR-code-modal{
    .qr-img-box{
        display: flex;
        justify-content: center;
    }
    .ant-modal-footer{
        display: none !important;
    }
}
</style>
<style scoped >
.observer-lbrary-pages{
    background: #fff;
}
.btn-box{
    display: flex;
    justify-content: flex-end;
}
.blue-btn{
    border: 1px solid #5ca3e5 !important;
    background-color: #5ca3e5 !important;
    color: #fff !important;
}
.red-btn{
    border: 1px solid #ed5565 !important;
    background-color: #ed5565 !important;
}





</style>